<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>
    <title>快速发布</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/common.css"/>
    <style>
        body {
            background: #f3f3f3;
            font-size: 14px;
        }

        .contain {
            position: relative;
            margin-bottom: 70px;
        }

        .menuRgiht {
            float: right;
            margin-right: 20px;
        }

        #scroller {
            width: 100%;
        }

        .aui-list-view {
            overflow: hidden;
        }

        .aui-list-view:after {
            border: none;
        }

        textarea {
            padding: 2px 8px;
            border: none;
            height: 80px;
            overflow-y: auto;
            margin-top: 5px;
        }

        .aui-list-view i.aui-iconfont {
            color: #000;
        }

        .addPic {
            font-size: 45px !important;
        }

        .picList li {
            max-height: 120px;
            /*overflow: hidden;*/
            width: 32%;
            margin-right: 2%;
            float: left;
            margin-bottom: 8px;
            position: relative;
        }

        .picList li:nth-of-type(3n) {
            margin-right: 0;
        }

        .picList li img {
            width: 100%;
            max-height: 120px;
        }

        .pic {
            max-height: 140px;
            overflow: hidden;
            padding-bottom: 0;
        }

        .liInfoPIc.pic {
            max-height: 270px;
            overflow: hidden;
            padding-bottom: 0;
        }

        .picGroup {
            text-align: center;
            background: #f5f5f5;
            padding: 5px;
            width: 32%;
            /*float: left;*/
            display: table;
            height: 120px;
            margin-bottom: 10px;
        }

        .picGroupCell {
            display: table-cell;
            vertical-align: middle;
        }

        footer {
            position: fixed;
            bottom: 0;
            width: 100%;
        }

        .pickerToTop .aui-list-view,
        .pickerToTop2 .aui-list-view {
            margin: 0;
        }

        .youfeiInput {
            padding: 0 !important;
            margin: 0 !important;
            margin-right: 10px !important;;
            width: 50px !important;
        }

        .spanYoufei {
            display: none;
        }
    </style>
</head>
<body>
<div class="contain">
    <ul class="aui-list-view">
        <li class="aui-list-view-cell" tapmode onclick="openToTwo('releaseCategory_win')">
            <a class="aui-arrow-right">
                类目（必填）
                <span class="menuRgiht setCategory validate" name="category">(必选)选择类目</span>
            </a>
        </li>

        <li class="aui-list-view-cell pic">
            <ul class="picList deleUl ulSlidePic" id="image-upload">
                <!--<li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="../../image/tese.jpg"></li>-->
                <!--<li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="../../image/login_bg.png">
                </li>
                <li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="../../image/tese.jpg"></li>
                <li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="../../image/login_bg.png">
                </li>
                <li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="../../image/tese.jpg"></li>
                <li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="../../image/login_bg.png">
                </li>
                <li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="../../image/tese.jpg"></li>-->
            </ul>
            <div class="picGroup " tapmode data-type="slidePic" onclick="add_pic('image-upload', 3,this)">
                <div class="picGroupCell">
                    <p><img src="../../image/addPic.png"></p>

                    <p>添加图片</p>

                    <p><em class="picSlideNum">0</em>/3</p>
                </div>
            </div>
        </li>
        <li class="aui-list-view-cell">
            标题（必填）
            <textarea name="title" oninput="checkTitle(this)" onpropertychange="checkTitle(this)" class="proName validate" placeholder="商品标题，不超过30个字"></textarea>
        </li>
    </ul>
    <ul class="aui-list-view">
        <!--<li class="aui-list-view-cell" tapmode onclick="openToTwo('releaseFormat_win')">-->
        <li class="aui-list-view-cell" tapmode onclick="setFormat()">
            <a class="aui-arrow-right">
                商品规格
                <span class="menuRgiht setFormate validate" name="format">(必选)未设置</span>
            </a>
        </li>
    </ul>
    <ul class="aui-list-view">
        <li class="aui-list-view-cell" tapmode onclick="setPrice()">
            <a class="aui-arrow-right">
                价格库存
                <span class="menuRgiht setPrice validate" name="price">(必选)未设置</span>
            </a>
        </li>
        <li class="aui-list-view-cell  validate" data-type="youfei" name="youfei"  tapmode onclick="setYoufei(this)">
            <a class="aui-arrow-right">
                运费
                <span class="menuRgiht youfeiType" name="youfei">(必选)未设置</span>

            </a>
        </li>
    </ul>
    <ul class="aui-list-view">
        <li class="aui-list-view-cell">
            商品详情（选填）
            <textarea name="" class="proInfoContent" placeholder="详细描述您的商品"></textarea>
        </li>
        <li class="aui-list-view-cell liInfoPIc pic">
            <ul class="picList deleUl ulInfoPic" id="infoPic-upload">
                <!--<li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="../../image/tese.jpg"></li>-->

            </ul>
            <div class="picGroup" tapmode data-type="infoPic" onclick="add_pic('infoPic-upload', 6,this)">
                <div class="picGroupCell">
                    <p><img src="../../image/addPic.png"></p>

                    <p>添加详情图</p>

                    <p><em class="picInfoNum">0</em>/6</p>
                </div>
            </div>
        </li>
    </ul>
    <ul class="aui-list-view">
        <li class="aui-list-view-cell" tapmode onclick="setProAttr()">
            <a class="aui-arrow-right">
                商品特殊属性
                <span class="menuRgiht proType">正常商品</span>
            </a>
        </li>
    </ul>
</div>
<footer class="aui-nav" >
    <div class="myBtn cancel" tapmode onclick="resetAll()">重置所有</div>
    <div class="myBtn  confirm" tapmode onclick="makeSure(this)">确认发布</div>


</footer>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/doT.min.js"></script>
<script type="text/javascript" src="../../script/jquery-1.11.3.js"></script>
<script type="text/javascript" src="../../script/mui.js"></script>
<script type="text/javascript" src="../../script/index.js"></script>
<!--<script type="text/javascript" src="../../script/lhcCommon.js"></script>-->
<script type="text/javascript">
    var imageNum = 0, picInfoNum = 0, type = "";//infoPic
    var categoryId, categoryText;//分类id和名字
    var colors, sizes;//颜色和大小属性
    var attrJson, leastCount;//价格大小和起订量
    var express=1;//是否包邮
    var proAttr = 5;//5为正常
    var slideImgsJson = "", infoImgHtml = "";//图片拼接地址
    //index和len如果相等表示那块图片上传完成，如果主图和详情图都完成可以操作下步
    var slideSendPicIndex = 0, infoSendPicIndex = 0, slideSendPicLen, infoSendPicLen;//上传图片的时候，主图和详情图上传到第几张

    var slideSendFinish = false;//主图是否上传完成
    var content="";//详情内容
    var proCount=0;//商品数量
    var showPrice=0;//商品显示的价格
    apiready = function () {
        api.parseTapmode();
        getStorageAll();
        //接收分类的监听
        api.addEventListener({
            name: "setCategory"
        }, function (ret) {
            if (ret.value && ret) {
                categoryId = ret.value.categoryId;
                $(".setCategory").text(ret.value.categoryText);
                $(".setCategory").removeClass("validate");
            }
        })
        //接收属性的监听
        api.addEventListener({
            name: "releaseFormat"
        }, function (ret) {
            if (ret.value && ret) {
                colors = ret.value.colors;
                sizes = ret.value.sizes;
                $(".setFormate").text("颜色，尺寸已设置");
                $(".setFormate").removeClass("validate");
                //修改规格，清除价格缓存
                clearPriceLocationStorage();
                //价格要重新设置
                if(!$(".setPrice").hasClass("validate")){
                    $(".setPrice").addClass("validate");
                    $(".setPrice").html("<em style='color:red'>规格已修改，请重新设置价格</em>")
                }

            }
        })
        //接收价格设置的属性
        api.addEventListener({
            name: "releasePrice"
        }, function (ret) {
            if (ret.value && ret) {
                attrJson = ret.value.attrJson;
                proCount=ret.value.proCount;
                leastCount = ret.value.leastCount;

                showPrice=ret.value.showPrice;
                $(".setPrice").text("价格，库存已设置");
                $(".setPrice").removeClass("validate");
//                alert(JSON.stringify(attrJson))
            }
        })

    }
    // 邮费设置
    function setYoufei(obj) {
        api.actionSheet({
            title: "设置邮费",
            buttons: ["包邮费", "不包邮费"]
//            buttons: ["包邮费"]
        }, function (ret, err) {
            if (ret.buttonIndex == 1) {
                $(obj).removeClass("validate");
                $(".youfeiType").text("包邮费");
                express=2;
            }
            else if(ret.buttonIndex == 2) {
                $(obj).removeClass("validate");
                $(".youfeiType").text("不包邮费");
                express=1;
            }
        })
    }
    //买家出邮费
    function checkFloat(obj) {
        var value = $(obj).val().trim();
        if (!isNumberFloat(value)) {
            $(obj).val("");
            api.toast({
                msg: "请输入正确格式！"
            })
        } else {
            youfeiPrice = value;
        }
    }
    // 商品列别设置
    function changeProType(obj) {
        $(".proType").text($(obj).text());
        hidePicker();
    }
    // 删除选择的图片
    function delePic(obj) {
        var imageId = $(obj).attr('data-imageId');
        $api.rmStorage('_' + imageId);
        var isInfo = $(obj).parent().parent().hasClass("ulInfoPic");//单击的删除的按个部分的
        if (isInfo) {
            picInfoNum--;
            uploadNum("infoPic");
        } else {
            imageNum--;
            uploadNum("slidePic");
        }
        $(obj).parent().remove();
    }

    function add_pic(index, max, obj) {
        api.actionSheet({
            title: '请选择图片来源',
            cancelTitle: '取消',
            buttons: ['相册选取', '相机拍摄']
        }, function (ret, err) {
//            判断是单击了那个图片上传
            type = $(obj).attr("data-type");
            var uploadType;
            //判断还可以选择几张图片上传
            if (max == "6") {
//                表示详情上传
                max = max - picInfoNum;
            } else {
//                主图上传
                max = max - imageNum;
            }
            if (max == 0) {
                api.toast({
                    msg: '图片已超过最多图片！',
                    duration: 1000,
                    location: 'middle'
                });
                return;
            }
            var winWidth = api.winWidth;
            var listHeight = winWidth / 3 - 12;
            if (ret.buttonIndex == 1) {
//                if ((/android/gi).test(navigator.appVersion)) {
                if (1) {
                    var album = api.require('UIMediaScanner');
                    album.open({
                        column: 3,
                        max: max,
                        sort: {
                            key: 'time',
                            order: 'desc'
                        },
                        texts: {
                            stateText: '*',
                            cancelText: '取消',
                            finishText: '完成'
                        },
                        styles: {
                            bg: '#fff',
                            mark: {
                                icon: '',
                                position: 'bottom_right',
                                size: 20
                            },
                            nav: {
                                bg: '#FF8F00',
                                stateColor: '#ffffff',
                                stateSize: 18,
                                cancleBg: '#FF8F00',
                                cancelColor: '#ffffff',
                                cancelSize: 18,
                                finishBg: '#FF8F00',
                                finishColor: '#ffffff',
                                finishSize: 18
                            }
                        },
                        exchange: true
                    }, function (ret) {
                        if (ret) {
                            var photoList = $api.byId(index);
                            var list = ret.list;
                            api.toast({
                                msg: '正在加载图片',
                                duration: 1000,
                                location: 'middle'
                            });
                            for (var i in list) {
                                var item = list[i];

                                var imgDom = $api.dom('#'+index+' .pics[src="' + item.path + '"]');
//                                var imgDom = $api.dom('.pics[src="' + item.path + '"]');
                                if (!imgDom) {
                                    /*$api.prepend(photoList, '<li class="li_pics" data-src="' + item.path + '" style="position:relative"><p class="state" id="' + item.path + '">正在上传</p><img class="pics" src="' + item.path + '"/><div style="display:block;height:20px;line-height:20px;text-align:center;width:20px;background:url(../image/del.png) no-repeat center center;background-size:60%;background-color:rgba(0,0,0,.6);color:#fff;position:absolute;bottom:0;right:0;z-index:8000" onclick="removePhoto(this)"></div></li>');*/
                                    $api.prepend(photoList, '<li><span class="deleIcon" data-imageId="image' + imageNum + '" tapmode onclick="delePic(this)"></span><img class="pics" src="' + item.path + '"></li>');
                                    api.parseTapmode();
                                }else{
                                    api.toast({
                                        msg:"图片已存在"
                                    })
                                    return false;
                                }
                                //uploadImage(item.path)发布再上传
                                if (type == "infoPic") {
                                    picInfoNum++;
                                } else {
                                    imageNum++;
                                }
                                uploadNum(type);
                            }

                        }
                    });
                } else {
                    //苹果相册
                    api.getPicture({
                        sourceType: 'album',
                        encodingType: 'jpg',
                        mediaValue: 'pic',
                        destinationType: 'url',
                        allowEdit: false,
                        quality: 60,
                        targetWidth: 300,
                        saveToPhotoAlbum: true
                    }, function (ret, err) {
                        var photoList = $api.byId(index);
                        if (ret.data) {
                            /*$api.prepend(photoList, '<li class="li_pics" data-src="' + ret.data + '" style="position:relative"><p class="state" id="' + ret.data + '">正在上传</p><img class="pics" src="' + ret.data + '"/><div style="display:block;height:20px;line-height:20px;text-align:center;width:20px;background:url(../image/del.png) no-repeat center center;background-size:60%;background-color:rgba(0,0,0,.6);color:#fff;position:absolute;bottom:0px;right:0;z-index:8000" onclick="removePhoto(this)"></div></li>');*/
                            $api.prepend(photoList, '<li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="' + ret.data + '"><input type="hidden" id="images0" value=""></li>');
                            api.parseTapmode();
                        }
                        //uploadImage(ret.data)发布再上传
                        if (type == "infoPic") {
                            picInfoNum++;
                        } else {
                            imageNum++;
                        }
                        uploadNum(type);
                    });
                }

            } else if (ret.buttonIndex == 2) {
                api.getPicture({
                    sourceType: 'camera',
                    encodingType: 'jpg',
                    mediaValue: 'pic',
                    destinationType: 'url',
                    allowEdit: false,
                    quality: 60,
                    targetWidth: 300,
                    saveToPhotoAlbum: true
                }, function (ret, err) {
                    var photoList = $api.byId(index);
                    if (ret.data) {
                        /*$api.prepend(photoList, '<li class="li_pics" data-src="' + ret.data + '" style="position:relative"><p class="state" id="' + ret.data + '">正在上传</p><img class="pics" src="' + ret.data + '"/><div style="display:block;height:20px;line-height:20px;text-align:center;width:20px;background:url(../image/del.png) no-repeat center center;background-size:60%;background-color:rgba(0,0,0,.6);color:#fff;position:absolute;bottom:0px;right:0;z-index:8000" onclick="removePhoto(this)"></div></li>');*/
                        $api.prepend(photoList, '<li><span class="deleIcon" tapmode onclick="delePic(this)"></span><img src="' + ret.data + '"><input type="hidden" id="images0" value=""></li>');
                        api.parseTapmode();
                        if (type == "infoPic") {
                            picInfoNum++;
                        } else {
                            imageNum++;
                        }
                        uploadNum(type);
                        //uploadImage(ret.data)发布再上传
                    } else {
                        api.toast({
                            msg: "拍照操作失败，请重新操作",
                            location: 'middle'
                        })
                    }
                });
            }
        });
    }

    // 上传图片
    /**
     *
     * @param imgPath  图片的本地地址
     * @param index 标记下标上传服务器
     */
    function uploadImage(imgPath, index) {
        //alert(JSON.stringify(imgPath)); return false;
//        alert("c"+imgPath);
        var img = new Image();
        img.src = imgPath;
        //图片路径
//        alert(imageNum);
        img.onload = function () {
//            alert(imageNum);
            //生成比例
            var w = this.width, h = this.height, scale = w / h;
            w = 640 || w;
            h = w / scale;
            //生成canvas
            var canvas = document.createElement('canvas');
            var ctx = canvas.getContext('2d');
            $api.attr(canvas, 'width', '' + w + '');
            $api.attr(canvas, 'height', '' + h + '');
            ctx.drawImage(this, 0, 0, w, h);
            var base64 = canvas.toDataURL('image/jpeg');
            getStorageAll();
            //上传图片
            var upData = {
                userName: user_name,
                base64: base64,
            }
            var url = 'Mall/imageUpload';
            ajaxRequest(url, 'post', upData, function (ret, err) {
//                alert(imageNum);
                if (ret.status == 1) {
                    if (!slideSendFinish) {
                        //主图没上传完成
                        slideImgsJson += '"thumb' + (index + 1) + '":' + '"' + ret.msg + '"';

                        slideSendPicIndex++;
                        if (slideSendPicIndex != slideSendPicLen) {
                            slideImgsJson += ","
                        }
                        if (slideSendPicIndex == slideSendPicLen) {
                            //当主图上传完成后开始上传详情图
                            slideSendFinish = true;
                            //监听发送，开始上传详情图
                            api.sendEvent({
                                name: "sendInfoPic",
                                extra: {
                                    start: true
                                }
                            })
                        }
                    } else {
                        //开始上上传详情图
                        infoSendPicIndex++;
                        infoImgHtml += "<img src='" + ret.msg + "'>";
                        if (infoSendPicIndex == infoSendPicLen) {
                            hideLoading();
                            //这里表示图片已全部上传完成
                            //这个可以对接数据库借口
                            slideSendPicIndex = 0, infoSendPicIndex = 0, slideSendFinish = false;
                            sendData();

                        }
                    }

                    return ret.msg

                } else {
                    //$api.remove($api.dom('.li_pics[data-src="' + imgPath + '"]'));
                    return "";
                }
            })
        }
    }

    //更新添加图片下面的数字
    function uploadNum(type) {
        if (type == "slidePic") {
            $(".picSlideNum").text(imageNum);
        } else {
            $(".picInfoNum").text(picInfoNum);
        }
    }
    //设置价格
    function setPrice() {
        if ((!colors) && (!sizes)) {
            api.toast({
                msg: "请先设置商品规格",
                location: "middle"
            })
        } else {
            api.openWin({
                name: "setPrice",
                url: "releasePrice_win.html",
                pageParam: {
                    colors: colors,
                    sizes: sizes
                }
            })
        }
    }
function setFormat() {
    api.openWin({
        name:"setFormat",
        url:'releaseFormat_win.html',
        pageParam:{
            colors:colors,
            sizes:sizes
        }
    })
}
    //设置商品属性
    function setProAttr() {

        api.actionSheet({
            title: "设置商品属性",
            buttons: ["尾货", "断码", "小批量", "残次品", "正常商品"]
        }, function (ret, err) {

            if (ret.buttonIndex == 1) {
                $(".proType").text("尾货");
            } else if (ret.buttonIndex == 2) {
                $(".proType").text("断码");
            } else if (ret.buttonIndex == 3) {
                $(".proType").text("小批量");
            } else if (ret.buttonIndex == 4) {
                $(".proType").text("残次品");
            } else if (ret.buttonIndex == 5) {
                $(".proType").text("正常商品");
            }
            proAttr = ret.buttonIndex;
        })
    }
    //确认发布
    function makeSure(obj) {
//        sendData();
//        alert($(".ulSlidePic").find("img"))


        if(checkAll()){
            showLoading();
            $(obj).removeAttr("onclick");
            $(obj).addClass("disable")
            $(".cancel").removeAttr("onclick");
            $(".cancel").addClass("disable");
            uploadAllImage();//上传主图和详情图
        }

    }
    function uploadAllImage() {
        //获取柱图和详情图的个数，跟slideSendPicIndex相等表示主图上传完成，  然后监听这两个都完成就可以下步
        slideSendPicLen = $(".ulSlidePic").find("img").length;
        infoSendPicLen = $(".ulInfoPic").find("img").length;
        $(".ulSlidePic").find("img").each(function (index) {
            //先一张一张循环上传主图，上传完主图在上传详情图
            uploadImage($(this).attr("src"), index);
        })
        //接收上传完主图发过来的监听，开始上传详情图
        api.addEventListener({
            name: "sendInfoPic"
        }, function (ret) {
            $(".ulInfoPic").find("img").each(function (index) {
                uploadImage($(this).attr("src"), index);//返回服务器端的地址
            })
        })
    }
    //发送数据到服务器对接借口
    function sendData() {
        var thumb = JSON.parse("{" + slideImgsJson + "}");
        var data = {};
        data['userName'] = user_name;
        data['categoryId'] = categoryId;
        data['title'] = $(".proName").val();
        data['thumb1'] = thumb["thumb1"];
        data['thumb2'] = thumb["thumb2"];
        data['thumb3'] = thumb["thumb3"];
        data['price'] = showPrice;
        data['spec'] =attrJson;
        data['express'] = express;
        data['wholesale_num'] = leastCount;
//        alert(attrJson)
//        data['spec']='[   {     "name1": "颜色",     "spec1": "红色",     "name2": "大小",     "spec2": "大码",     "amount": "12",     "money": "12.25",     "pic": "http://192.168.3.4/file/upload/201611/28/104916901.jpg"   }]';

        //获取详情内容
        if($(".proInfoContent").val().trim()!=""){
            content+="<div style='margin-bottom:10px;'>"+$(".proInfoContent").val().trim()+"</div>";
        }
        content+=infoImgHtml;
        data['content'] = content;
        data['goodsType'] = proAttr;
        data['amount'] = proCount;
        data['attribute'] = '{"面料": "棉"}';
        var url = 'Mall/goodsAdd';
//        alert(JSON.stringify(data))
        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {
//                alert("商品发布成功！")
                hideLoading();
                location.reload();
                api.toast({
                    msg: "商品发布成功",
                    duration: 2000,
                    location: 'middle'
                });
                //发布成功后清除价格缓存
                clearPriceLocationStorage();
            } else {
                hideLoading();
//                alert(JSON.stringify(data))
                api.toast({
                    msg: "商品发布失败，"+ret.msg,
//                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
                slideImgsJson = "", infoImgHtml = "";//图片拼接地址
                $(".confirm").attr("onclick","makeSure(this)");
                $(".confirm").removeClass("disable");
                $(".cancel").attr("onclick","resetAll()");
                $(".cancel").removeClass("disable");

//                setTimeout(function () {
//                    window.location.reload();
//                },1500)

            }
        })
    }
//    发布页面前检查各个必须填的项目
    function checkAll() {
        var name="",result=true;
        var msg="";
        $(".contain").find(".validate").each(function () {
            name=$(this).attr("name");
            result=false;
            switch (name){
                case "category":
                    msg="请设置类目！";
                    break;
                case "title":
                    msg="请填写标题！";
                    $(this).focus();
                    break;
                case "format":
                    msg="请设置商品规格！";
                    break;
                case "price":
                    msg="请设置价格库存！";
                    break;
                case "youfei":
                    msg="请选择运费模式！";
                    break;
                case "youfeiInput":
                    $(this).focus();
                    msg="请设置运费！";
                    break;
                default:
                    msg="未知错误，请仔细检查！";
                    break;
            }
            api.toast({
                msg:msg
            })
            return;
        })
        if($(".ulSlidePic").find("img").length==0){
            api.toast({
                msg:"请上传商品主图!"
            })
            return;
        }
        if($(".ulInfoPic").find("img").length==0){
            api.toast({
                msg:"请上传商品详情图!"
            })
            return;
        }
        return result;

    }
    //检查标题
    function checkTitle(obj) {
        var titleValue=$(obj).val().trim();
        if(titleValue==""){
            //如果为空加上要验证的class
            if(!$(obj).hasClass("validate")){
                $(obj).addClass("validate");
            }
        }else{
            $(obj).removeClass("validate");
            if(titleValue.length>30){
                $(obj).val(titleValue.substr(0,30));
                api.toast({
                    msg:"已超出30字数！"
                })
            }
        }
    }
    //重置所有
    function resetAll() {
        if(confirm("确定要重置所有吗？")){
            location.reload();
            api.toast({
                msg:"重置成功"
            })
        }
    }
    function clearPriceLocationStorage() {
        $api.setStorage("_attrJson","");
        $api.setStorage("_leastCount","");
        $api.setStorage("_showPrice","");
    }
</script>
</html>
